|
Impact AIT |
Return to Index
›FTP Client - VB6 - Browse VP Files
Using Visual Basic 6 for FTP Client
Browse the vision program files on an Datalogic device
You can use this Visual Basic application (which contains a Microsoft Internet Transfer Control) to browse files on a vision device from the client PC.
Notes:
The default AIT root distribution folder for this application is:
/Datalogic/IMPACT/AIT/FTP Client.
Create the Visual
Basic program
1.
Start
Microsoft Visual Basic 6.0. (Note: This sample code is in the AIT distribution
subfolder /VisualBasic6/Example1/Project.)
2.
Select
a new Standard EXE project type.
3.
From
the project explorer, select Project1 and press F4.
4.
Rename
the project to "Browse_IMPACT_Programs"
5.
Press
Ctrl-T to show the component selection dialog box.
6.
Select
Microsoft Internet Transfer Control 6.0 and click OK.
7.
Select
the Inet control from the toolbox and place it on the form.
8.
Change
the Inet control's Password property to "0197411".
9.
Change
the Inet control's Protocol property to "icFTP".
10.
Change
the Inet control's UserName property to "PptImpact" (This property is
case sensitive.)
11.
Add
a button to the form. Change the name and caption to "Scan".
12.
Add
a label to the form. Change the name to "Status".
13.
Add
a textbox to the form. Change the name to "IPAddress" and change the
text property to your device’s IP address.
14.
Add
a listbox to the form. Change the to "programList".
15.
Double
click on the Form and remove any existing code in the window.
16.
Enter
the following code. (You may select and copy the code from this page, then
paste it into the form.)
Option Explicit
Private Sub Form_Load()
Status.Caption = ""
End Sub
Private Sub Inet1_StateChanged(ByVal
State As Integer)
'this will parse the data received from the "LS" command
'and at it to the programList ListBox
Dim strBuffer As String
Dim firstLoop As Boolean
Dim i As Integer
Dim Element As String
Dim Filename As String
Dim lastBreak As Integer
Dim newBreak As Integer
Dim count As Integer
Select Case State
Case icError '11
Status.Caption = "Error: " & _
Inet1.ResponseCode & vbCrLf &
Inet1.ResponseInfo
Case icConnecting '3
Status.Caption = "Connecting"
Case icDisconnected '10
Status.Caption = "Disconnecting"
Case icRequestSent '6
Status.Caption = "Request Sent"
Case icResponseCompleted '12
Status.Caption = Inet1.ResponseInfo
Scan.Caption = "Scan"
strBuffer = Inet1.GetChunk(512)
firstLoop = True
If programList.ListCount = 0 Then
For i = 1 To Len(strBuffer)
If (Len(strBuffer) - i) > 2 Then
Element = Mid$(strBuffer, i, 1)
If Element = Chr(13) Then
If firstLoop = True Then
firstLoop = False
Filename =
Mid$(strBuffer, 1, (i - 1))
programList.AddItem
Filename
lastBreak = i
Else
newBreak =
lastBreak + 2
lastBreak = i
Filename = Mid$(strBuffer,
newBreak, (count - 1))
programList.AddItem Filename
count = 0
End If
count = 0
Else
count = count + 1
End If
End If
Next
Else
Status.Caption = strBuffer
End If
Me.MousePointer = vbDefault
End Select
End Sub
Private Sub Scan_Click()
Me.MousePointer = vbHourglass
programList.Clear
Dim filtering As String
Scan.Caption = "Scanning"
On Error GoTo ErrorHandler
'connect to Datalogic device, change to the VisionProgram directory
'and "browse directory" operation
Inet1.RemoteHost = IPAddress.Text
Inet1.Execute , "CD VisionPrograms"
Do While Inet1.StillExecuting
DoEvents
Loop
Inet1.Execute , "LS *.vp"
Exit Sub
ErrorHandler:
Scan.Caption = "Scan"
Me.MousePointer = vbDefault
MsgBox "Unable To Connect To IMPACT Device",
vbExclamation, "IMPACT File Browser"
End Sub
17.
Save
the project.
18.
Make
an executable file from the project then run the executable. What does the program User Interface
look like?
19.
When
you press the Scan button, the Visual Basic program connects to the Datalogic
device using FTP protocol. It then sends a Change Directory command (changing
to the VisionPrograms directory), then an LS command to list the files in that
directory. As the Inet control receives data, it parses it and adds the
filenames to the listbox. INet control messages are displayed in the label
control.
©2003-2013 Datalogic Automation Inc. All Rights Reserved